﻿using AutoCAD;
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CADAutoPlot
{
    class DrawWindow
    {
        private Dictionary<string, double> windowData;
        private Dictionary<string, Object> windowData1;
        private Point startPoint,startPoint1,startPoint2;
        private int type;
        private string windowType;
        private int graphOffset;
        private AcadModelSpace modelSpace;
        private DrawComponment drawComponment;
        private DrawComponementsByRandomParams drawMultiComponent;
        private Preview previewImg;


        public DrawWindow(AcadModelSpace ms,Dictionary<string, double> data, Preview previewImg)
        {
            this.modelSpace = ms;
            this.type = (int)(Common.GetValuesForKey(data,"IDC_WINDOW_TYPE"));
            this.previewImg = previewImg;
            this.windowData = data;
            this.graphOffset = 500;
            this.drawComponment = new DrawComponment(modelSpace, type,windowData, this.previewImg);

            //俯视图
            this.startPoint = new Point(100.0, 100.0, 0.0);
            //正视图
            this.startPoint1 = new Point(startPoint.getX(), startPoint.getY() - graphOffset, startPoint.getZ());
            //侧视图
            this.startPoint2 = new Point(startPoint.getX() + drawComponment.upperLBoardLength + graphOffset, startPoint.getY() - graphOffset, startPoint.getZ());

            
        }
        public DrawWindow(AcadModelSpace ms, Dictionary<string, Object> data, Preview previewImg)
        {
            this.modelSpace = ms;
            this.windowType =  Common.GetObjectValuesForKey(data, "IDC_WINDOW_TYPE").ToString();
            this.previewImg = previewImg;
            this.windowData1 = data;
            this.graphOffset = 500;
            this.drawMultiComponent = new DrawComponementsByRandomParams(modelSpace, 0,windowData1, this.previewImg);
            //俯视图
            this.startPoint = new Point(100.0, 100.0, 0.0);
            //正视图
            this.startPoint1 = new Point(startPoint.getX(), startPoint.getY() - graphOffset, startPoint.getZ());
            //侧视图
            this.startPoint2 = new Point(startPoint.getX() + drawMultiComponent.upperLBoardLength + graphOffset, startPoint.getY() - graphOffset, startPoint.getZ());
        }
        public void DrawMultiWindows()
        {
            bool withTBar = windowType.IndexOf('T') == -1 ? false : true;
            string wndType = windowType.Replace("T","");
            Console.WriteLine("DrawMultiWindows");
            DrawWindowByParams(wndType, withTBar);
        }
        public void DrawWindowByParams(string windowType,bool withTBar)
        {
            //画俯视图
            drawMultiComponent.DrawLBoard(startPoint, 0, withTBar);
            startPoint = new Point(startPoint.getX() + drawMultiComponent.lboardLHeight2 + drawMultiComponent.windowGap, startPoint.getY() - drawMultiComponent.lboardLHeight, startPoint.getZ());
            drawMultiComponent.DrawEdge(startPoint, 0,withTBar,windowType);
            
            //画正视图
            drawMultiComponent.DrawLBoard(startPoint1, 1,withTBar);
            startPoint1 = new Point(startPoint1.getX() + drawMultiComponent.lboardLHeight2, startPoint1.getY() - drawMultiComponent.lboardLHeight2 - drawMultiComponent.windowGap, startPoint1.getZ());
            drawMultiComponent.DrawEdge(startPoint1, 1,withTBar,windowType);

            startPoint1 = new Point(startPoint1.getX() + drawMultiComponent.hidePlainEdgeWidth + drawMultiComponent.windowGap, startPoint1.getY(), startPoint1.getZ());
            drawMultiComponent.DrawBoard(startPoint1, 1,withTBar);
            startPoint1 = new Point(startPoint1.getX(), startPoint1.getY() - drawMultiComponent.upperBoardWidth, startPoint1.getZ());
            drawMultiComponent.DrawLeaf(startPoint1, 1,withTBar);
            //startPoint1 = new Point(startPoint1.getX() - drawMultiComponent.hidePlainEdgeWidth, startPoint1.getY() + drawMultiComponent.upperBoardWidth, startPoint1.getZ());
            //drawMultiComponent.DrawHinge(startPoint1, 1,withTBar);
            
            //画侧视图
            drawMultiComponent.DrawLBoard(startPoint2, 2,withTBar);
            startPoint2 = new Point(startPoint2.getX() + drawMultiComponent.lboardLHeight, startPoint2.getY() - (drawMultiComponent.lboardLHeight2) - drawMultiComponent.windowGap, startPoint2.getZ());
            drawMultiComponent.DrawBoard(startPoint2, 2,withTBar);
            drawMultiComponent.DrawLeaf(startPoint2, 2,withTBar);
            

        }
        public void Draw()
        {
            switch(type)
            {
                case 0:
                    DrawSingleWindow();
                    break;
                case 1:
                    DrawDoubleWindow();
                    break;
                case 2:
                    DrawTripleWindow();
                    break;
                case 3: //window With single T-Bar
                    DrawTripleWindowWithSingleTBar();
                    break;
                case 4: //window With double T-Bar
                    DrawTripleWindowWithDoubleTBar();
                    break;
                default:
                    break;
            }
        }

        private void DrawSingleWindow()
        {
            
            //画俯视图
            
            drawComponment.DrawLBoard(startPoint, 0);
            startPoint = new Point(startPoint.getX() + drawComponment.upperLBoardLength - drawComponment.lboardLHeight2 - drawComponment.windowGap,startPoint.getY() - drawComponment.lboardLHeight,startPoint.getZ());
            drawComponment.DrawEdge(startPoint, 0);
            
            //画正视图
            drawComponment.DrawLBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + (drawComponment.upperLBoardLength - drawComponment.lboardLHeight2 - drawComponment.windowGap), startPoint1.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint1.getZ());
            drawComponment.DrawEdge(startPoint1, 1);
            
            startPoint1 = new Point(startPoint1.getX() - drawComponment.hidePlainEdgeWidth - drawComponment.windowWidth, startPoint1.getY(), startPoint1.getZ());
            drawComponment.DrawBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX(),startPoint1.getY() - drawComponment.upperBoardWidth,startPoint1.getZ());
            drawComponment.DrawLeaf(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.hidePlainEdgeWidth + drawComponment.windowWidth, startPoint1.getY() + drawComponment.upperBoardWidth, startPoint1.getZ());
            drawComponment.DrawHinge(startPoint1, 1);

            //画侧视图
            drawComponment.DrawLBoard(startPoint2,2);
            startPoint2 = new Point(startPoint2.getX() + drawComponment.lboardLHeight,startPoint2.getY() - (drawComponment.lboardLHeight2) - drawComponment.windowGap, startPoint2.getZ());
            drawComponment.DrawBoard(startPoint2, 2);
            drawComponment.DrawLeaf(startPoint2, 2);
            
        }
        private void DrawDoubleWindow()
        {
            //画俯视图
            drawComponment.DrawLBoard(startPoint, 0);
            startPoint = new Point(startPoint.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint.getY() - drawComponment.lboardLHeight, startPoint.getZ());
            drawComponment.DrawEdge(startPoint, 0);
            //画正视图
            drawComponment.DrawLBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint1.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint1.getZ());
            drawComponment.DrawEdge(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.hidePlainEdgeWidth, startPoint1.getY(), startPoint1.getZ());
            drawComponment.DrawBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX(), startPoint1.getY() - (drawComponment.upperBoardWidth), startPoint1.getZ());
            drawComponment.DrawLeaf(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() - drawComponment.hidePlainEdgeWidth, startPoint1.getY() + drawComponment.upperBoardWidth, startPoint1.getZ());
            drawComponment.DrawHinge(startPoint1, 1);
            //画侧视图
            drawComponment.DrawLBoard(startPoint2, 2);
            startPoint2 = new Point(startPoint2.getX() + drawComponment.lboardLHeight, startPoint2.getY() - (drawComponment.lboardLHeight2) - drawComponment.windowGap, startPoint2.getZ());
            drawComponment.DrawBoard(startPoint2, 2);
            drawComponment.DrawLeaf(startPoint2, 2);
        }
        private void DrawTripleWindow()
        {
            //画俯视图
            drawComponment.DrawLBoard(startPoint, 0);
            startPoint = new Point(startPoint.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap,startPoint.getY() - drawComponment.lboardLHeight,startPoint.getZ());
            drawComponment.DrawEdge(startPoint, 0);
            //画正视图
            drawComponment.DrawLBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint1.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint1.getZ());
            drawComponment.DrawEdge(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.hidePlainEdgeWidth,startPoint1.getY(),startPoint1.getZ());
            drawComponment.DrawBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX(), startPoint1.getY() - (drawComponment.upperBoardWidth), startPoint1.getZ());
            drawComponment.DrawLeaf(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() - drawComponment.hidePlainEdgeWidth, startPoint1.getY() + drawComponment.upperBoardWidth, startPoint1.getZ());
            drawComponment.DrawHinge(startPoint1, 1);
            //画侧视图
            drawComponment.DrawLBoard(startPoint2, 2);
            startPoint2 = new Point(startPoint2.getX() + drawComponment.lboardLHeight, startPoint2.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint2.getZ());
            drawComponment.DrawBoard(startPoint2, 2);
            drawComponment.DrawLeaf(startPoint2, 2);
        }
        private void DrawTripleWindowWithSingleTBar()
        {
            //画俯视图
            drawComponment.DrawLBoard(startPoint, 0);
            
            startPoint = new Point(startPoint.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint.getY() - drawComponment.lboardLHeight, startPoint.getZ());
            drawComponment.DrawEdge(startPoint, 0);
            
            //画正视图
            drawComponment.DrawLBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint1.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint1.getZ());
            drawComponment.DrawEdge(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.hidePlainEdgeWidth, startPoint1.getY(), startPoint1.getZ());

            drawComponment.DrawBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX(), startPoint1.getY() - (drawComponment.upperBoardWidth), startPoint1.getZ());
            drawComponment.DrawLeaf(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() - drawComponment.hidePlainEdgeWidth, startPoint1.getY() + drawComponment.upperBoardWidth, startPoint1.getZ());
            drawComponment.DrawHinge(startPoint1, 1);

            //画侧视图
            drawComponment.DrawLBoard(startPoint2, 2);
            startPoint2 = new Point(startPoint2.getX() + drawComponment.lboardLHeight, startPoint2.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint2.getZ());
            drawComponment.DrawBoard(startPoint2, 2);
            drawComponment.DrawLeaf(startPoint2, 2);
        }
        private void DrawTripleWindowWithDoubleTBar()
        {
            
            //画俯视图
            drawComponment.DrawLBoard(startPoint, 0);
            startPoint = new Point(startPoint.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint.getY() - drawComponment.lboardLHeight, startPoint.getZ());
            drawComponment.DrawEdge(startPoint, 0);
            //画正视图
            
            drawComponment.DrawLBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX() + drawComponment.lboardLHeight2 + drawComponment.windowGap, startPoint1.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint1.getZ());
            drawComponment.DrawEdge(startPoint1, 1);
            
            startPoint1 = new Point(startPoint1.getX() + drawComponment.hidePlainEdgeWidth, startPoint1.getY(), startPoint1.getZ());
            drawComponment.DrawBoard(startPoint1, 1);
            startPoint1 = new Point(startPoint1.getX(), startPoint1.getY() - (drawComponment.upperBoardWidth), startPoint1.getZ());
            drawComponment.DrawLeaf(startPoint1, 1);
            
            startPoint1 = new Point(startPoint1.getX() - drawComponment.hidePlainEdgeWidth, startPoint1.getY() + drawComponment.upperBoardWidth, startPoint1.getZ());
            //画侧视图
            drawComponment.DrawLBoard(startPoint2, 2);
            startPoint2 = new Point(startPoint2.getX() + drawComponment.lboardLHeight, startPoint2.getY() - drawComponment.lboardLHeight2 - drawComponment.windowGap, startPoint2.getZ());
            drawComponment.DrawBoard(startPoint2, 2);
            drawComponment.DrawLeaf(startPoint2, 2);
        }
    }
}
